<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户列表页面</title>
    <link th:href="@{/css/bootstrap.css}" rel="stylesheet">
</head>
<body>

<div class="container">
    <h1>用户列表</h1>
    <form class="row g-3" th:action="@{/queryUser}" method="get">
        <div class="col-auto">
            <label class="visually-hidden">用户名</label>
            <input type="text" name="name" class="form-control" id="staticEmail2" placeholder="用户名"
                   th:value="${params?.name}">
        </div>
        <div class="col-auto">
            <label class="visually-hidden">电话</label>
            <input type="text" name="phone" class="form-control" id="inputPassword2" placeholder="电话"
                   th:value="${params?.phone}">
        </div>
        <div class="col-auto"><label>部门：</label></div>
        <div class="col-auto">

            <select name="deptCode" id="deptCode" class="form-select">
                <option value="">---请选择部门---</option>
                <option
                        th:each="d:${dept}"
                        th:text="${d.deptName}"
                        th:value="${d.deptCode}"
                        th:selected="${d.deptCode}==${params.deptCode}"
                >生产部
                </option>
            </select>
        </div>
        <div class="col-auto">
            <button type="submit" class="btn btn-primary mb-3">提交</button>
        </div>
    </form>
    <div>
        <form th:action="@{/upload}" method="post" enctype="multipart/form-data">
            上传文件：<input type="file" name="file">
            <button type="submit"> 上传</button>
        </form>
    </div>
    <form th:action="@{/catchDelUser}" method="get">
        <table class="table">
            <tr>
                <td>全选/全不选</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>电话</td>
                <td>所在部门</td>
                <td>操作</td>

            </tr>
            <tbody>
            <tr th:each="u:${pageInfo.list}">
                <td><input type="checkbox" name="ids" th:value="${u.id}"></td>
                <td th:text="${u.name}"></td>
                <td th:text="${u.age}"></td>
                <td th:text="${u.phone}"></td>
                <td th:text="${u.dept?.deptName}">生产部</td>
                <td><a class="btn btn-primary" th:href="@{/userDetail(id=${u.id})}">详细信息</a>
                    <a class="btn btn-success" th:href="@{/userEdit(id=${u.id})}">编辑</a>
                    <a class="btn btn-danger" th:href="@{/userDelete(id=${u.id})}">删除</a>
                    <a class="btn btn-warning" th:href="@{/userMark(id=${u.id})}">标记删除</a>
                </td>

            </tr>

            </tbody>
        </table>
        <nav>
            <ul class="pagination">
                <li class="page-item">
                    <a class="page-link" th:if="${not pageInfo.isFirstPage}"
                       th:href="@{${'queryUser'}(pageNum=${pageInfo.pageNum-1},pageSize=${pageInfo.pageSize})}"
                       aria-label="Previous">
                        <span aria-hidden="true">上一页</span>
                    </a>
                    <a class="page-link" th:if="${pageInfo.isFirstPage}" href="javascript:void(0);"
                       aria-label="Previous">
                        <span aria-hidden="true">上一页</span>
                    </a>
                </li>

                <li th:class="${pageInfo.pageNum eq pageNo ? 'page-item active' : 'page-item'}"
                    th:each="pageNo : ${#numbers.sequence(1, pageInfo.pages)}">
                    <a class="page-link" th:if="${pageInfo.pageNum eq pageNo}" href="javascript:void(0);">
                        <span th:text="${pageNo}"></span>
                    </a>

                    <a class="page-link" th:if="${not (pageInfo.pageNum eq pageNo)}"
                       th:href="@{${'queryUser'}(pageNum=${pageNo},pageSize=${pageInfo.pageSize})}">
                        <span th:text="${pageNo}"></span>
                    </a>
                </li>

                <li class="page-item">
                    <a class="page-link" th:if="${not pageInfo.isLastPage}"
                       th:href="@{${'queryUser'}(pageNum=${pageInfo.pageNum+1},pageSize=${pageInfo.pageSize})}"
                       aria-label="Next">
                        <span aria-hidden="true">下一页</span>
                    </a>
                    <a class="page-link" th:if="${pageInfo.isLastPage}" href="javascript:void(0);" aria-label="Next">
                        <span aria-hidden="true">下一页</span>
                    </a>
                </li>
            </ul>
        </nav>
        <div class="text-center">
            <a th:href="@{/createUser}" class="btn btn-warning">添加新用户</a>
            <button type="submit" class="btn btn-danger">全部删除</button>
            <button type="submit" class="btn btn-success" th:formaction="downloadUsers">导出用户表</button>
        </div>

    </form>


</div>
</body>
</html>